#include "StdAfx.h"
#include "Grass.h"
#include "globalSDL.h"
#include "GlobalInfo.h"
CGrass::CGrass(void)
:m_nMinY(0),m_nMaxY(SCREEN_HEIGHT)
,m_nV(2),m_nDitch(0)
{
	m_rect1.x = 0;
	m_rect1.y = 0;
	m_rect1.w = 200;
	m_rect1.h = 2;
	
	m_rect2.x = 0;
	m_rect2.y = 0;
	m_rect2.w = 200;
	m_rect2.h = 2;
}

CGrass::~CGrass(void)
{
}
void CGrass::Init()
{
	m_colorBlue = SDL_MapRGB(g_pSurface->format, 0 , 0 , 255 );
}
void CGrass::SetPos( int x, int y )
{
	m_rect1.x = x;
	m_rect1.y = y;
	m_rect2.x = x;
	m_rect2.y = y;
}
void CGrass::OnDraw()
{
	SDL_Rect rect1 = m_rect1;
	SDL_Rect rect2 = m_rect2;
	SDL_FillRect(g_pSurface, &rect1,m_colorBlue);
	SDL_FillRect(g_pSurface, &rect2,m_colorBlue);
}
void CGrass::SetLimit( int min, int max )
{

}
void CGrass::OnMove()
{
	int y = m_rect1.y - m_nV;
	if( y <= 0 )
	{
		y = SCREEN_HEIGHT;
		Repos();
	}
	m_rect1.y = y;
	m_rect2.y = y;
}
void CGrass::Repos()
{
	int width = rand() % SCREEN_WIDTH;
	m_rect1.w = width;
	m_rect2.x = width + m_nDitch;
	m_rect2.w = SCREEN_WIDTH - width - m_nDitch;
}
void CGrass::SetVertical( int v )
{
	m_nV = v;
}
int CGrass::GetVertical() const
{
	return m_nV;
}
int CGrass::GetX() const
{
	return m_rect1.x;
}
int CGrass::GetY() const
{
	return m_rect1.y;
}
bool CGrass::CollideSth( int x, int y, int w, int h )
{
	bool bResult = false;

	if( (m_rect1.x + m_rect1.w > x) || ( x + w > m_rect2.x ) )
	{
		if( m_rect1.y > y && m_rect1.y < y + h )
		{
			bResult = true;
		}
	}
	return bResult;
}
void CGrass::SetDitch( int nDitch )
{
	m_nDitch = nDitch;
}